package com.hmall.order.interceptor;

import com.search.common.dto.util.BaseLocal ;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class OrderInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //todo 因为没有添加请求头 这里只能全部true放行
        String auth = request.getHeader("Auth");

        //todo 因为目前 请求头中 没有id数据 直接给了个id
        BaseLocal.threadLocal.set(2l);

        String au = request.getHeader("AU");
        System.out.println(au);
        System.out.println("经过了拦截器");
//        if (auth!=null) {
//            if (auth.equals("2")) {
//                return true;
//            }
//        }
        return true;
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        BaseLocal.threadLocal.remove();
    }
}